/*
 * utils.c
 *
 *  Created on: 2011-11-8
 *      Author: zhangtao
 */
#include <gl_utils.h>

#include <math.h>
void calculateNormal(GLfloat normal[], GLfloat vertexes[9]){
	GLfloat x0 = vertexes[3] - vertexes[0];
	GLfloat y0 = vertexes[4] - vertexes[1];
	GLfloat z0 = vertexes[5] - vertexes[2];
	GLfloat x1 = vertexes[6] - vertexes[3];
	GLfloat y1 = vertexes[7] - vertexes[4];
	GLfloat z1 = vertexes[8] - vertexes[5];
	GLfloat x2 = y0 * z1 - z0 * y1;
	GLfloat y2 = z0 * x1 - x0 * z1;
	GLfloat z2 = x0 * y1 - y0 * x1;
	GLdouble length = sqrt(x2 * x2 + y2 * y2 + z2 * z2);
	normal[0] = x2 / length;
	normal[1] = y2 / length;
	normal[2] = z2 / length;
}


